<template>
	<view class="container">
		<view
			:key="item.id"
			v-for="item in dataList"
			class="list-cell b-b"
			hover-class="cell-hover"
			:hover-stay-time="50">
			<view class="cell">
				<view class="cell-row">
					<text class="cell-tit">{{item.title}}</text>
					<text class="cell-tip plus" v-if="item.amount >= 0">+{{item.amount}}</text>
					<text class="cell-tip minus" v-else>{{item.amount}}</text>
				</view>
				<view class="content">
					{{item.createTime|formatTime}}
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
	export default {
		computed: {
			...mapState(['app', 'user'])
		},
		data() {
			return {
				loadingType: 'more', //加载更多状态
				typeId: 0,
				dataList: [],
				dataPage: {
					totalCount: 0,
					limit: 10,
					page: 1
				},
			}
		},
		// 下拉刷新
		onPullDownRefresh(){
			this.loadData('refresh');
			uni.stopPullDownRefresh();
		},
		// 加载更多
		onReachBottom(){
			if (this.loadingType != 'nomore') {
				if (this.dataPage.totalCount == this.dataList.length()) {
					this.loadingType = 'nomore';
				} else {
					this.page += 1;
					this.loadingType = 'loading';
					this.loadData();
				}
			}
		},
		async onLoad(options){
			this.typeId = options.typeId;
			this.loadData();
		},
		methods: {
			async loadData(type){
				if (type == 'refresh') {
					this.dataPage.page = 1;
				}
				let res = await this.util.request({
					url: '/v1/user_score/score_log/my/' + this.typeId,
					data: {
						page: this.dataPage.page,
						limit: this.dataPage.limit
					},
					method: 'get'
				});
				if (res.code == 200) {
					if (type == 'refresh') {
						this.dataList = res.data.dataList;
					} else {
						this.dataList = this.dataList.concat(res.data.dataList);
					}
					if (this.dataPage.totalCount == this.dataList.length) {
						this.loadingType = 'nomore';
					}
				} else {
					this.util.showToast({
						title: res.msg,
						icon: 'loading',
						duration: 2000
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	.list-cell {
		display:flex;
		align-items:baseline;
		padding: 20upx $page-row-spacing;
		line-height:60upx;
		position:relative;
		background: #fff;
		justify-content: space-between;
		&.cell-hover {
			background:#fafafa;
		}
		&.b-b:after {
			left: 30upx;
		}
		&.m-t {
			margin-top: 16upx; 
		}
		.cell-more {
			align-self: center;
			font-size:$font-lg;
			color:$font-color-light;
			margin-left:10upx;
		}
		.cell {
			width: 100%;
			.cell-row {
				display: flex;
				.cell-tit {
					flex: 1;
					font-size: $font-base + 2upx;
					color: $font-color-dark;
					margin-right:10upx;
				}
				.cell-tip {
					font-size: $font-base;
					color: $font-color-light;
				}
				.plus {
					color: $uni-color-primary;
				}
				.minus {
					color: $uni-text-color;
				}
			}
			.content {
				width: 100%;
				color: $font-color-light;
			}
		}
		switch {
			transform: translateX(16upx) scale(.84);
		}
	}
</style>
